package arcsoft.common.log;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.util.Log;

public class Logger implements LogAPI{
	
	public static final int OS_UNKOWN  = 0;
	public static final int OS_ANDROID = OS_UNKOWN+1;
	public static final int OS_WINDOWS = OS_ANDROID+1;
	
	private LogAPI api = null;
	private String tag = null;
	private final SimpleDateFormat dateFormator = new SimpleDateFormat("MM-dd HH:mm:ss");
	public Logger(String TAG, int platform){
		
		switch(platform) {
		case OS_ANDROID:
			api = new LogOfAndroid();
			break;
		case OS_WINDOWS:
			api = new LogOfWin32();
			break;
		default:
			api = new LogOfWin32();
		}
		
		if(TAG!=null) tag = TAG;
		else tag = " ";
	}
	
	@Override
	public void e(String context) {
		if(context==null)context="null";
		context = getData()+" [ERR] "+tag+" "+context;
		api.e(context);
	}
	
	@Override
	public void w(String context) {
		if(context==null)context="null";
		context = getData()+" [WAR] "+tag+" "+context;
		api.w(context);
	}
	
	@Override
	public void i(String context) {
		if(context==null)context="null";
		context = getData()+" [INF] "+tag+" "+context;
		api.i(context);
	}
	
	@Override
	public void d(String context) {
		if(context==null)context="null";
		context = getData()+" [DEB] "+tag+" "+context;
		api.d(context);
	}
	
	private String getData() {
		return dateFormator.format(new Date());
	}
	
	class LogOfAndroid implements LogAPI {
		
		private final String aTag = "QA";
		
		@Override
		public void d(String context) {
			Log.d(aTag,context);
			
		}

		@Override
		public void i(String context) {
			Log.e(aTag,context);
			
		}

		@Override
		public void w(String context) {
			Log.w(aTag,context);
			
		}

		@Override
		public void e(String context) {
			Log.e(aTag,context);
		}
		
	}
	
	class LogOfWin32 implements LogAPI {
		
		private final String aTag = "QA";
		
		@Override
		public void d(String context) {
			System.out.println(context);
			
		}

		@Override
		public void i(String context) {
			System.out.println(context);
			
		}

		@Override
		public void w(String context) {
			System.out.println(context);
			
		}

		@Override
		public void e(String context) {
			System.err.println(context);
		}
		
	}

}
